﻿using System;
namespace Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000 {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="omt2", Namespace="http://producers.ehma-10000000.xtee.riik.ee/producer/ehma-10000000", Target=typeof(Omt2))]
    public class Omt2Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IOmt2 clazz;
        
        public Omt2Serializer(IOmt2 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("rafid");
            if (clazz.Rafid!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Rafid))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Rafid");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("nameraf");
            if (clazz.Nameraf!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nameraf))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nameraf");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("nameplayraf");
            if (clazz.Nameplayraf!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nameplayraf))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nameplayraf");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("raftime");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.Raftime))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("rafpayo");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Rafpayo))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="rafid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omt2>rafid");
                }
                clazz.Rafid = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("rafid")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omt2>rafid", Reader.LocalName);
            }
            if (Reader.LocalName=="nameraf") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omt2>nameraf");
                }
                clazz.Nameraf = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nameraf")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omt2>nameraf", Reader.LocalName);
            }
            if (Reader.LocalName=="nameplayraf") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omt2>nameplayraf");
                }
                clazz.Nameplayraf = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nameplayraf")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omt2>nameplayraf", Reader.LocalName);
            }
            if (Reader.LocalName=="raftime") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omt2>raftime");
                }
                clazz.Raftime = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("raftime")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omt2>raftime", Reader.LocalName);
            }
            if (Reader.LocalName=="rafpayo") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omt2>rafpayo");
                }
                clazz.Rafpayo = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("rafpayo")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omt2>rafpayo", Reader.LocalName);
            }
        }
    }
}
